const MyPromise = require('./MyPromise.js');

let promise = new MyPromise((resolve, reject) => {
    // setTimeout(() => {
    resolve('成功-success')
    // }, 2000)
    // reject('失败-fail')
})

function other() {
    return new MyPromise((resolve, reject) => {
        resolve('other')
    })
}
// let p1 = promise.then(value => {
//     console.log(value);
//     // return p1;
//     // throw new Error('ssssss error')
// }, reason => {
//     console.log(reason);
//     return 1000
// }).then(value => {
//     console.log('value');
//     console.log(value);
// })
// promise.then().then().then(value => console.log(value), reason => console.log(reason))

function p1() {
    return new MyPromise((resolve, reject) => {
        setTimeout(() => {
            reject('p22')
        }, 1000)
    })
}

function p2() {
    return new MyPromise((resolve, reject) => {
        // resolve('p2')
        reject('p22')
    })
}

// MyPromise.all(['a', 'b', p1(), p2(), 'c']).then(value => {
//     console.log(value);
// })

// MyPromise.resolve(p1()).then(value => console.log(value))
// MyPromise.resolve(10000000).then(value => console.log(value)) 

MyPromise.reject(p1()).then(value => console.log(value), reason => { console.log(reason, "p[") })
MyPromise.reject(10000000).then(value => console.log(value), reason => { console.log(reason, "p[") })

// p2().finally(() => {
//     console.log('finally');
//     return p1();
// }).then(value => {
//     console.log(value);
// }, reason => {
//     console.log(reason)
// })

// p2().then(value => {
//     console.log(value)
// }).catch(reason => {
//     console.log(reason)
// })

